package com.ruoyi.system.controller;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.stream.Collectors;
import org.apache.commons.compress.utils.Lists;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.baomidou.mybatisplus.core.toolkit.BeanUtils;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.Exit;
import com.ruoyi.system.domain.Important;
import com.ruoyi.system.domain.Stop;
import com.ruoyi.system.domain.TotalSite;
import com.ruoyi.system.service.IExitService;
import com.ruoyi.system.service.IImportantService;
import com.ruoyi.system.service.IStopService;
import com.ruoyi.system.service.ITotalSiteService;
import com.ruoyi.system.vo.Geojson;
import com.ruoyi.system.vo.Geometry;
import com.ruoyi.system.vo.Properties;

import cn.hutool.core.bean.BeanUtil;

/**
 * 全部总数据Controller
 * 
 * @author zhangkai
 * @date 2021-11-22
 */
@RestController
@RequestMapping("/tietasystem/totalsite")
public class TotalSiteController extends BaseController
{
	@Autowired
    private ITotalSiteService totalSiteService;
    
    @Autowired
    private IExitService exitService;
    
    @Autowired
    private IImportantService importantService;
    
    @Autowired
    private IStopService stopService;

    /**
     * 查询全部总数据列表
     */
    @PreAuthorize("@ss.hasPermi('tietasystem:totalsite:list')")
    @GetMapping("/list")
    public TableDataInfo list(TotalSite totalSite)
    {
        startPage();
        if(totalSite.getVersion() != null) {
        String newDateRange = totalSite.getVersion().replaceAll("-", "").replaceAll(":", "").replaceAll(" ", "").substring(0,12);
        totalSite.setVersion(newDateRange);
        }
        List<TotalSite> list = totalSiteService.selectTotalSiteList(totalSite);
        return getDataTable(list);
    }

    /**
     * 导出全部总数据列表
     */
    @PreAuthorize("@ss.hasPermi('tietasystem:totalsite:export')")
    @Log(title = "全部总数据", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(TotalSite totalSite)
    {
        List<TotalSite> list = totalSiteService.selectTotalSiteList(totalSite);
        ExcelUtil<TotalSite> util = new ExcelUtil<TotalSite>(TotalSite.class);
        return util.exportExcel(list, "全部总数据数据");
    }

    /**
     * 获取全部总数据详细信息
     */
    @PreAuthorize("@ss.hasPermi('tietasystem:totalsite:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(totalSiteService.selectTotalSiteById(id));
    }

    /**
     * 新增全部总数据
     */
    @PreAuthorize("@ss.hasPermi('tietasystem:totalsite:add')")
    @Log(title = "全部总数据", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TotalSite totalSite)
    {
        return toAjax(totalSiteService.insertTotalSite(totalSite));
    }

    /**
     * 修改全部总数据
     */
    @PreAuthorize("@ss.hasPermi('tietasystem:totalsite:edit')")
    @Log(title = "全部总数据", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TotalSite totalSite)
    {
        return toAjax(totalSiteService.updateTotalSite(totalSite));
    }

    /**
     * 删除全部总数据
     */
    @PreAuthorize("@ss.hasPermi('tietasystem:totalsite:remove')")
    @Log(title = "全部总数据", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(totalSiteService.deleteTotalSiteByIds(ids));
    }
    
    @GetMapping("/importTemplate")
    public AjaxResult importTemplate()
    {
        ExcelUtil<TotalSite> util = new ExcelUtil<TotalSite>(TotalSite.class);
        return util.importTemplateExcel("全部数据");
    }
    
    @Log(title = "全部总数据", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('tietasystem:totalsite:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file,String dateRange) throws Exception
    {
        ExcelUtil<TotalSite> util = new ExcelUtil<TotalSite>(TotalSite.class);
        List<TotalSite> totalList = util.importExcel(file.getInputStream());
        String operName = getUsername();
        String message = totalSiteService.importTotal(totalList, operName,dateRange);
        return AjaxResult.success(message);
    }
}
